package com.group1.bookmanagement.action;

import java.io.File;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.group1.bookmanagement.action.UploadAction;
import com.group1.bookmanagement.domain.Photo;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Controller("uploadAction")
@Scope("prototype")
public class UploadAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private File file;

	/**
	 * 上传图片
	 * @return
	 */
	public String uploadPhoto() {
		HttpServletRequest request = ServletActionContext.getRequest();
		Photo photo = new Photo(file);
		photo.upload(request);
		ActionContext context = ActionContext.getContext();
		context.put("photo", photo);

		return SUCCESS;
	}

	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

}
